package com.vm.activity;

import java.util.ArrayList;
import java.util.List;

import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentActivity;
import android.support.v4.view.ViewPager;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ImageButton;
import android.widget.RadioButton;

import com.vm.adapter.FragAdapter;
import com.vm.fragment.HasGetPointFragment;
import com.wwt.app.R;

public class IntergralActivity extends FragmentActivity {
	protected static final String TAG = "IntergralActivity";

	RadioButton rbtn_not_getting;
	RadioButton rbtn_have_geted;
	ImageButton imgbtn_back;

	private ViewPager vp;
	private FragAdapter adapter;
	List<Fragment> fragments;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.get_points_nav);

		init();
		initChilds();
	}

	public void init() {
		rbtn_not_getting = (RadioButton) findViewById(R.id.rbtn_not_getting);
		rbtn_have_geted = (RadioButton) findViewById(R.id.rbtn_have_geted);
		imgbtn_back = (ImageButton) findViewById(R.id.imgbtn_back);

		rbtn_not_getting.setOnClickListener(rbtnClickListener);
		rbtn_have_geted.setOnClickListener(rbtnClickListener);
		imgbtn_back.setOnClickListener(rbtnClickListener);
	}

	private void initChilds() {
		fragments = new ArrayList<Fragment>();
		fragments.add(new HasGetPointFragment());
		vp = (ViewPager) findViewById(R.id.viewpager);
		adapter = new FragAdapter(getSupportFragmentManager(), fragments);
		vp.setAdapter(adapter);
		
 
		// 设置最大缓存数
		// 默认缓存2个页面,当出现第三个页面会删掉之前缓存中的一个.
		vp.setOffscreenPageLimit(2);
		vp.setCurrentItem(0);

		// fm = getSupportFragmentManager();// 获取fragment管理工具类
		// replace(new FoundFragment());
	}

	OnClickListener rbtnClickListener = new OnClickListener() {

		@Override
		public void onClick(View v) {
			if (v == rbtn_not_getting) {
				vp.setCurrentItem(0);
			} else if (v == rbtn_have_geted) {
				vp.setCurrentItem(1);
			} else if (v == imgbtn_back) {
				onBackPressed();
			}
		}
	};

	/**
	 * 手机自带返回按钮监听
	 */
	@Override
	public void onBackPressed() {
		super.onBackPressed();

	}
}
